<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
      
    
    
      
    
  <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
  <link href="//cdn.bootcss.com/pace/1.0.2/themes/blue/pace-theme-flash.min.css" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
    
  
  <link href="//cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet" type="text/css">







  

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Node,">





  <link rel="alternate" href="/atom.xml" title="TiX" type="application/atom+xml">






<meta name="description" content="对Node.js进行简单的身份验证，jwt全称jsonwebtoken…">
<meta name="keywords" content="Node">
<meta property="og:type" content="article">
<meta property="og:title" content="教你在express中使用jwt与passport-jwt做token派发与验证">
<meta property="og:url" content="https://gitee.com/L1334101793/教你在express中使用jwt做token派发与验证/index.html">
<meta property="og:site_name" content="TiX">
<meta property="og:description" content="对Node.js进行简单的身份验证，jwt全称jsonwebtoken…">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-07-10T02:42:25.996Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="教你在express中使用jwt与passport-jwt做token派发与验证">
<meta name="twitter:description" content="对Node.js进行简单的身份验证，jwt全称jsonwebtoken…">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"right","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://gitee.com/L1334101793/教你在express中使用jwt做token派发与验证/">





  <title>教你在express中使用jwt与passport-jwt做token派发与验证 | TiX</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">TiX</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Stay Hungry, Stay Foolish</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/L1334101793/教你在express中使用jwt做token派发与验证/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="TiX">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="TiX">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">教你在express中使用jwt与passport-jwt做token派发与验证</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-07-10T09:49:56+08:00">
                2019-07-10
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o">本文阅读</i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>人次
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>对Node.js进行简单的身份验证，jwt全称jsonwebtoken…<br><a id="more"></a></p>
<h3 id="安装jsonwebtoken-passport-jwt"><a href="#安装jsonwebtoken-passport-jwt" class="headerlink" title="安装jsonwebtoken,passport-jwt"></a>安装jsonwebtoken,passport-jwt</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#推荐淘宝镜像安装</span></span><br><span class="line">npm install jsonwebtoken</span><br><span class="line">npm install passport</span><br><span class="line">npm install passport-jwt</span><br></pre></td></tr></table></figure>
<h3 id="主入口注册"><a href="#主入口注册" class="headerlink" title="主入口注册"></a>主入口注册</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">const passport = require(<span class="string">"passport"</span>);</span><br><span class="line"><span class="comment">#passport初始化,很重要。</span></span><br><span class="line">server.use(passport.initialize());</span><br><span class="line">require(<span class="string">"./libs/passport"</span>)(passport);</span><br></pre></td></tr></table></figure>
<h3 id="登录模块中使用"><a href="#登录模块中使用" class="headerlink" title="登录模块中使用"></a>登录模块中使用</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line">const express = require(<span class="string">'express'</span>);</span><br><span class="line">const mysql = require(<span class="string">'mysql'</span>);</span><br><span class="line">const common = require(<span class="string">'../../libs/common'</span>);</span><br><span class="line">const jwt = require(<span class="string">"jsonwebtoken"</span>);</span><br><span class="line">const CryptoJS  = require(<span class="string">"crypto-js"</span>);</span><br><span class="line"></span><br><span class="line">var db = mysql.createPool(&#123; host: <span class="string">'localhost'</span>, user: <span class="string">'root'</span>, password: <span class="string">'xxxxx'</span>, database: <span class="string">'xxx'</span> &#125;);</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> decrypt(content, key)&#123;</span><br><span class="line">    var sKey = CryptoJS.enc.Utf8.parse(key);</span><br><span class="line">    var decrypt = CryptoJS.AES.decrypt(content, sKey, &#123;mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7&#125;);</span><br><span class="line">    <span class="built_in">return</span> CryptoJS.enc.Utf8.stringify(decrypt).toString();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">module.exports = <span class="function"><span class="title">function</span></span> () &#123;</span><br><span class="line">    var router = express.Router();</span><br><span class="line">    router.post(<span class="string">'/userlogin'</span>, (req, res) =&gt; &#123;</span><br><span class="line">        var username = req.query.loginName;</span><br><span class="line">        //解密，加密过程看博客 https://l1334101793.gitee.io/记录vue-element的一些经验/</span><br><span class="line">        var passwordSecret = decrypt(req.query.password,common.key);</span><br><span class="line">        //md5加密，防拖库</span><br><span class="line">        var password = common.md5(passwordSecret + common.MD5_SUFFIX);</span><br><span class="line">        db.query(`SELECT * FROM admin_table WHERE admin_name=<span class="string">'$&#123;username&#125;'</span> &amp;&amp; admin_state!=<span class="string">'true'</span>`, (err, data) =&gt; &#123;</span><br><span class="line">            <span class="keyword">if</span> (err) &#123;</span><br><span class="line">                res.status(500).send(<span class="string">'数据库错误'</span>).end();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> &#123;</span><br><span class="line">              <span class="comment">#这里存储你想存的东西，之后会加密到被请求的接口，验证通过后会解密到req里。</span></span><br><span class="line">                const rule = &#123;id:data[0].GUID,name:username&#125;;</span><br><span class="line">                jwt.sign(rule,common.MD5_SUFFIX,&#123;expiresIn:7200&#125;,(err,token) =&gt; &#123;</span><br><span class="line">                  <span class="keyword">if</span>(err) throw err;</span><br><span class="line">                  res.json(&#123;</span><br><span class="line">                    code: 200,</span><br><span class="line">                    status: <span class="string">'success'</span>,</span><br><span class="line">                    message: <span class="string">'登录成功'</span>,</span><br><span class="line">                    username: username,</span><br><span class="line">                    token:  <span class="string">"Bearer "</span> + token   <span class="comment">#这里一定要加Bearer，后面一定要加空格！切记切记。</span></span><br><span class="line">                  &#125;);</span><br><span class="line">                &#125;)</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;);</span><br><span class="line">    <span class="built_in">return</span> router;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">#其中省略部分无关代码。</span></span><br><span class="line"><span class="comment">#common.js中的内容</span></span><br><span class="line">const crypto=require(<span class="string">'crypto'</span>);</span><br><span class="line">module.exports=&#123;</span><br><span class="line">    MD5_SUFFIX: <span class="string">'xxxx'</span>,  <span class="comment">#这里是自己的密钥</span></span><br><span class="line">    md5: <span class="keyword">function</span> (str)&#123;</span><br><span class="line">        var obj=crypto.createHash(<span class="string">'md5'</span>);</span><br><span class="line">        obj.update(str);</span><br><span class="line">        <span class="built_in">return</span> obj.digest(<span class="string">'hex'</span>);</span><br><span class="line">    &#125;,</span><br><span class="line">    key: <span class="string">'xxxx'</span>    <span class="comment">#这里也是自己密钥，两次密钥最好不一样</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<h3 id="使用mysql结合passport-jwt做用户验证"><a href="#使用mysql结合passport-jwt做用户验证" class="headerlink" title="使用mysql结合passport-jwt做用户验证"></a>使用mysql结合passport-jwt做用户验证</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#首先在公共js文件夹下新建passport.js</span></span><br><span class="line"><span class="comment">#在passport.js中写入</span></span><br><span class="line">const JwtStrategy = require(<span class="string">'passport-jwt'</span>).Strategy,</span><br><span class="line">  ExtractJwt = require(<span class="string">'passport-jwt'</span>).ExtractJwt;</span><br><span class="line"></span><br><span class="line">const keys = require(<span class="string">"../libs/common"</span>);   <span class="comment">#keys为一个密钥字段，自行设置</span></span><br><span class="line">const opts = &#123;&#125;</span><br><span class="line">opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();</span><br><span class="line">opts.secretOrKey = keys.MD5_SUFFIX;</span><br><span class="line"></span><br><span class="line">const mysql = require(<span class="string">'mysql'</span>);</span><br><span class="line">var db = mysql.createPool(&#123; host: <span class="string">'localhost'</span>, user: <span class="string">'root'</span>, password: <span class="string">'xxxxx'</span>, database: <span class="string">'xxxx'</span> &#125;);</span><br><span class="line"></span><br><span class="line">module.exports = passport =&gt; &#123;</span><br><span class="line">  passport.use(new JwtStrategy(opts, <span class="keyword">function</span>(jwt_payload, <span class="keyword">done</span>) &#123;</span><br><span class="line">    <span class="comment">#jwt_payload中会携带登录信息，此信息为</span></span><br><span class="line">    db.query(`SELECT * FROM admin_table WHERE admin_name=<span class="string">'$&#123;jwt_payload.name&#125;'</span> &amp;&amp; admin_state!=<span class="string">'true'</span>`, (err, data) =&gt; &#123;</span><br><span class="line">      <span class="keyword">if</span> (err) &#123;</span><br><span class="line">        res.status(500).send(<span class="string">'数据库错误'</span>).end();</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (data.length == 0) &#123;</span><br><span class="line">          <span class="built_in">return</span> <span class="keyword">done</span>(null, <span class="literal">false</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> &#123;</span><br><span class="line">          <span class="built_in">return</span> <span class="keyword">done</span>(null, data); <span class="comment">#这里会把在登录时候的加密字段传到使用的接口中</span></span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="最后一步，在请求接口时调用。"><a href="#最后一步，在请求接口时调用。" class="headerlink" title="最后一步，在请求接口时调用。"></a>最后一步，在请求接口时调用。</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">const passport = require(<span class="string">"passport"</span>);</span><br><span class="line"><span class="comment">#route  GET /admin/getroles</span></span><br><span class="line"><span class="comment">#desc   获取所有角色信息</span></span><br><span class="line"><span class="comment">#access Private jwt</span></span><br><span class="line">router.get(<span class="string">'/getroles'</span>, passport.authenticate(<span class="string">"jwt"</span>, &#123; session: <span class="literal">false</span> &#125;), (req, res) =&gt; &#123;</span><br><span class="line">  <span class="comment">#这个json返回你自己需要的东西。</span></span><br><span class="line">  res.json(&#123;</span><br><span class="line">    id: req.user[0].GUID,</span><br><span class="line">    name: req.user[0].admin_name,</span><br><span class="line">    role: req.user[0].admin_ownrole</span><br><span class="line">  &#125;)</span><br><span class="line">&#125;);</span><br><span class="line"><span class="comment">#这里通过了会返回上面的数据，没通过验证返回Unauthorized</span></span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wcpay.png" alt="TiX 微信支付">
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.png" alt="TiX 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Node/" rel="tag"># Node</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/前端面试易考题/" rel="next" title="前端面试易考题">
                <i class="fa fa-chevron-left"></i> 前端面试易考题
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/使用puppeteer爬取你想要的任何数据，所见即所得/" rel="prev" title="使用puppeteer爬取你想要的任何数据，所见即所得">
                使用puppeteer爬取你想要的任何数据，所见即所得 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">TiX</p>
              <p class="site-description motion-element" itemprop="description">个人学习记录，涉及前端，分享心得等。</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">21</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">12</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#安装jsonwebtoken-passport-jwt"><span class="nav-number">1.</span> <span class="nav-text">安装jsonwebtoken,passport-jwt</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#主入口注册"><span class="nav-number">2.</span> <span class="nav-text">主入口注册</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#登录模块中使用"><span class="nav-number">3.</span> <span class="nav-text">登录模块中使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用mysql结合passport-jwt做用户验证"><span class="nav-number">4.</span> <span class="nav-text">使用mysql结合passport-jwt做用户验证</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#最后一步，在请求接口时调用。"><span class="nav-number">5.</span> <span class="nav-text">最后一步，在请求接口时调用。</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2019 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">TiX</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user">访客</i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye">总访问</i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      人次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/jquery/2.1.3/jquery.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/fastclick/1.0.6/fastclick.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/jquery.lazyload/1.9.3/jquery.lazyload.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/velocity/1.2.3/velocity.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/velocity/1.2.3/velocity.ui.min.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/fancybox/2.1.5/jquery.fancybox.pack.js"></script>
  

  
  
    <script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.1/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
